function varargout = MonsterForm(varargin)
% MONSTERFORM M-file for MonsterForm.fig
%      MONSTERFORM, by itself, creates a new MONSTERFORM or raises the existing
%      singleton*.
%
%      H = MONSTERFORM returns the handle to a new MONSTERFORM or the handle to
%      the existing singleton*.
%
%      MONSTERFORM('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MONSTERFORM.M with the given input arguments.
%
%      MONSTERFORM('Property','Value',...) creates a new MONSTERFORM or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before MonsterForm_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to MonsterForm_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help MonsterForm

% Last Modified by GUIDE v2.5 03-Feb-2009 18:00:57

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @MonsterForm_OpeningFcn, ...
                   'gui_OutputFcn',  @MonsterForm_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before MonsterForm is made visible.
function MonsterForm_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to MonsterForm (see VARARGIN)

% Choose default command line output for MonsterForm
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes MonsterForm wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = MonsterForm_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit_name_Callback(hObject, eventdata, handles)
% hObject    handle to edit_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_name as text
%        str2double(get(hObject,'String')) returns contents of edit_name as a double


% --- Executes during object creation, after setting all properties.
function edit_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_class_Callback(hObject, eventdata, handles)
% hObject    handle to edit_class (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_class as text
%        str2double(get(hObject,'String')) returns contents of edit_class as a double


% --- Executes during object creation, after setting all properties.
function edit_class_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_class (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_initiative_Callback(hObject, eventdata, handles)
% hObject    handle to edit_initiative (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_initiative as text
%        str2double(get(hObject,'String')) returns contents of edit_initiative as a double


% --- Executes during object creation, after setting all properties.
function edit_initiative_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_initiative (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_hp_Callback(hObject, eventdata, handles)
% hObject    handle to edit_hp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_hp as text
%        str2double(get(hObject,'String')) returns contents of edit_hp as a double


% --- Executes during object creation, after setting all properties.
function edit_hp_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_hp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_speed_Callback(hObject, eventdata, handles)
% hObject    handle to edit_speed (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_speed as text
%        str2double(get(hObject,'String')) returns contents of edit_speed as a double


% --- Executes during object creation, after setting all properties.
function edit_speed_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_speed (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_ac_Callback(hObject, eventdata, handles)
% hObject    handle to edit_ac (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_ac as text
%        str2double(get(hObject,'String')) returns contents of edit_ac as a double


% --- Executes during object creation, after setting all properties.
function edit_ac_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_ac (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox_weapon.
function listbox_weapon_Callback(hObject, eventdata, handles)
% hObject    handle to listbox_weapon (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox_weapon contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox_weapon


% --- Executes during object creation, after setting all properties.
function listbox_weapon_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox_weapon (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox_armour.
function listbox_armour_Callback(hObject, eventdata, handles)
% hObject    handle to listbox_armour (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox_armour contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox_armour


% --- Executes during object creation, after setting all properties.
function listbox_armour_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox_armour (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox_feats.
function listbox_feats_Callback(hObject, eventdata, handles)
% hObject    handle to listbox_feats (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox_feats contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox_feats


% --- Executes during object creation, after setting all properties.
function listbox_feats_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox_feats (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox_skill.
function listbox_skill_Callback(hObject, eventdata, handles)
% hObject    handle to listbox_skill (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox_skill contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox_skill


% --- Executes during object creation, after setting all properties.
function listbox_skill_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox_skill (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox_item.
function listbox_item_Callback(hObject, eventdata, handles)
% hObject    handle to listbox_item (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox_item contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox_item


% --- Executes during object creation, after setting all properties.
function listbox_item_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox_item (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton_attack.
function pushbutton_attack_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_attack (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Open dialog-box
prompt = {'Enter the name or the ID of the new weapon:'};
dlg_title = 'New weapon';
answer = inputdlg(prompt,dlg_title);

% If no answer
if isempty(answer)
    return;
end

% Add to list
try
    if isempty(cell2mat(get(handles.popupmenu_attack,'string')))
        set(handles.popupmenu_attack,'string', answer);
    else
        t = [get(handles.popupmenu_attack,'string'); answer ];
        set(handles.popupmenu_attack,'string',t);
    end
catch
    t = [get(handles.popupmenu_attack,'string'); answer ];
    set(handles.popupmenu_attack,'string',t);
end


% --- Executes on button press in pushbutton_sabilities.
function pushbutton_sabilities_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_sabilities (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Open dialog-box
prompt = {'Enter the name or the ID of the new armour:'};
dlg_title = 'New armour';
answer = inputdlg(prompt,dlg_title);

% If no answer
if isempty(answer)
    return;
end

% Add to list
try
    if isempty(cell2mat(get(handles.popupmenu_sabilities,'string')))
        set(handles.popupmenu_sabilities,'string', answer);
    else
        t = [get(handles.popupmenu_sabilities,'string'); answer ];
        set(handles.popupmenu_sabilities,'string',t);
    end
catch
    t = [get(handles.popupmenu_sabilities,'string'); answer ];
    set(handles.popupmenu_sabilities,'string',t);
end



% --- Executes on button press in pushbutton_sattack.
function pushbutton_sattack_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_sattack (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Open dialog-box
prompt = {'Enter the name or the ID of the new feat:'};
dlg_title = 'New feat';
answer = inputdlg(prompt,dlg_title);

% If no answer
if isempty(answer)
    return;
end

% Add to list
try
    if isempty(cell2mat(get(handles.popupmenu_sattack,'string')))
        set(handles.popupmenu_sattack,'string', answer);
    else
        t = [get(handles.popupmenu_sattack,'string'); answer ];
        set(handles.popupmenu_sattack,'string',t);
    end
catch
    t = [get(handles.popupmenu_sattack,'string'); answer ];
    set(handles.popupmenu_sattack,'string',t);
end


% --- Executes on button press in pushbutton_proficiency.
function pushbutton_proficiency_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_proficiency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Open dialog-box
prompt = {'Enter the name or the ID of the new skill:'};
dlg_title = 'New skill';
answer = inputdlg(prompt,dlg_title);

% If no answer
if isempty(answer)
    return;
end

% Add to list
try
    if isempty(cell2mat(get(handles.popupmenu_proficiency,'string')))
        set(handles.popupmenu_proficiency,'string', answer);
    else
        t = [get(handles.popupmenu_proficiency,'string'); answer ];
        set(handles.popupmenu_proficiency,'string',t);
    end
catch
    t = [get(handles.popupmenu_proficiency,'string'); answer ];
    set(handles.popupmenu_proficiency,'string',t);    
end


% --- Executes on button press in pushbutton_feat.
function pushbutton_feat_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_feat (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Open dialog-box
prompt = {'Enter the name or the ID of the new item:'};
dlg_title = 'New item';
answer = inputdlg(prompt,dlg_title);

% If no answer
if isempty(answer)
    return;
end

% Add to list
try
    if isempty(cell2mat(get(handles.popupmenu_feat,'string')))
        set(handles.popupmenu_feat,'string', answer);
    else
        t = [get(handles.popupmenu_feat,'string'); answer ];
        set(handles.popupmenu_feat,'string',t);
    end
catch
    t = [get(handles.popupmenu_feat,'string'); answer ];
    set(handles.popupmenu_feat,'string',t);
end



function edit_str_Callback(hObject, eventdata, handles)
% hObject    handle to edit_str (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_str as text
%        str2double(get(hObject,'String')) returns contents of edit_str as a double


% --- Executes during object creation, after setting all properties.
function edit_str_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_str (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_dex_Callback(hObject, eventdata, handles)
% hObject    handle to edit_dex (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_dex as text
%        str2double(get(hObject,'String')) returns contents of edit_dex as a double


% --- Executes during object creation, after setting all properties.
function edit_dex_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_dex (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_con_Callback(hObject, eventdata, handles)
% hObject    handle to edit_con (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_con as text
%        str2double(get(hObject,'String')) returns contents of edit_con as a double


% --- Executes during object creation, after setting all properties.
function edit_con_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_con (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_int_Callback(hObject, eventdata, handles)
% hObject    handle to edit_int (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_int as text
%        str2double(get(hObject,'String')) returns contents of edit_int as a double


% --- Executes during object creation, after setting all properties.
function edit_int_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_int (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_wis_Callback(hObject, eventdata, handles)
% hObject    handle to edit_wis (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_wis as text
%        str2double(get(hObject,'String')) returns contents of edit_wis as a double


% --- Executes during object creation, after setting all properties.
function edit_wis_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_wis (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_cha_Callback(hObject, eventdata, handles)
% hObject    handle to edit_cha (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_cha as text
%        str2double(get(hObject,'String')) returns contents of edit_cha as a double


% --- Executes during object creation, after setting all properties.
function edit_cha_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_cha (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_for_Callback(hObject, eventdata, handles)
% hObject    handle to edit_for (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_for as text
%        str2double(get(hObject,'String')) returns contents of edit_for as a double


% --- Executes during object creation, after setting all properties.
function edit_for_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_for (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_ref_Callback(hObject, eventdata, handles)
% hObject    handle to edit_ref (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_ref as text
%        str2double(get(hObject,'String')) returns contents of edit_ref as a double


% --- Executes during object creation, after setting all properties.
function edit_ref_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_ref (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_wil_Callback(hObject, eventdata, handles)
% hObject    handle to edit_wil (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_wil as text
%        str2double(get(hObject,'String')) returns contents of edit_wil as a double


% --- Executes during object creation, after setting all properties.
function edit_wil_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_wil (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton_save.
function pushbutton_save_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get file and path name
[FileName,PathName] = uiputfile('*.mat','Save character!');

% Make structure
monster = struct( ...
    'name', get(handles.edit_name,'string'), ...
    'class', get(handles.edit_class,'string'), ...                                                              % Classes;Levels, - [F/3 C/1]
    'initiative', str2num(get(handles.edit_initiative,'string')), ...                                                       % size bonus
    'atr',struct(...
        'str',[str2num(get(handles.edit_str,'string')) str2num(get(handles.edit_str,'string'))],...
        'dex',[str2num(get(handles.edit_dex,'string')) str2num(get(handles.edit_dex,'string'))],...             % atributes           
        'con',[str2num(get(handles.edit_con,'string')) str2num(get(handles.edit_con,'string'))],...
        'int',[str2num(get(handles.edit_int,'string')) str2num(get(handles.edit_int,'string'))],...
        'wis',[str2num(get(handles.edit_wis,'string')) str2num(get(handles.edit_wis,'string'))],...
        'cha',[str2num(get(handles.edit_cha,'string')) str2num(get(handles.edit_cha,'string'))]), ...  
    'st',struct(...
        'for',[str2num(get(handles.edit_for,'string')) str2num(get(handles.edit_for,'string'))],...
        'ref',[str2num(get(handles.edit_ref,'string')) str2num(get(handles.edit_ref,'string'))],...
        'wil',[str2num(get(handles.edit_wil,'string')) str2num(get(handles.edit_wil,'string'))]), ...           % saving throws
    'hp', [str2num(get(handles.edit_hp,'string')) str2num(get(handles.edit_hp,'string'))], ...                  % heal points
    'ac', str2num(get(handles.edit_ac,'string')), ...                                                        	% ac
    'speed', str2num(get(handles.edit_speed,'string')), ...                                                     % speed
    'attack', [getPopUpMenu(handles.popupmenu_attack)], ...                                                       % weapons
    'sabilities',  [getPopUpMenu(handles.popupmenu_sabilities)], ...                                                       % armor
    'sattack', [getPopUpMenu(handles.popupmenu_sattack)], ...                                                         % feats
    'proficiency', [getPopUpMenu(handles.popupmenu_proficiency)], ...                                                        % skills
    'feat', [getPopUpMenu(handles.popupmenu_feat)], ...                                                         % other possessions
    'challenge', get(handles.edit_challenge,'string'), ...
    'treasure', get(handles.edit_treasure,'string'), ...
    'characteristic', get(handles.edit_characteristic,'string'), ...
    'sidereach', get(handles.edit_sidereach,'string'), ...
    'damage', get(handles.edit_damage,'string'), ...
    'bonus', [], ...                                           % all bonuses to throws [name, (what - how many)*, flag] !!!!!!!!!!!!!!!!!!!!!!!
    'buf', [] ...                                              % buffs [name, counter] !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
);

% Save structure
save([PathName FileName],'monster')




% --- Executes on button press in pushbutton_load.
function pushbutton_load_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_load (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Clear all values
clear(handles);

% Load file
[FileName,PathName] = uigetfile('*.mat','Select the mat-file!');
load([PathName '/' FileName])

% Set main values
set(handles.edit_name,'string',monster.name);
set(handles.edit_class,'string',monster.class);
set(handles.edit_initiative,'string',monster.initiative);
set(handles.edit_hp,'string',monster.hp(1));
set(handles.edit_speed,'string',monster.speed);
set(handles.edit_ac,'string',num2str(monster.ac));

set(handles.edit_challenge,'string',monster.challenge);
set(handles.edit_treasure,'string',monster.treasure);
set(handles.edit_characteristic,'string',monster.characteristic);
set(handles.edit_sidereach,'string',monster.sidereach);
set(handles.edit_damage,'string',monster.damage);
                           
% Set attributes
set(handles.edit_str,'string',monster.atr.str(1));
set(handles.edit_dex,'string',monster.atr.dex(1));
set(handles.edit_con,'string',monster.atr.con(1));
set(handles.edit_int,'string',monster.atr.int(1));
set(handles.edit_wis,'string',monster.atr.wis(1));
set(handles.edit_cha,'string',monster.atr.cha(1));

% Set saving throws
set(handles.edit_for,'string',monster.st.for(1));
set(handles.edit_ref,'string',monster.st.ref(1));
set(handles.edit_wil,'string',monster.st.wil(1));

% Set Attack
setPopUpMenu(handles.popupmenu_attack,monster.attack)
% Set S. Abilities
setPopUpMenu(handles.popupmenu_sabilities,monster.sabilities)
% Set S. Attacks
setPopUpMenu(handles.popupmenu_sattack,monster.sattack)
% Set Proficincies
setPopUpMenu(handles.popupmenu_proficiency,monster.proficiency)
% Set Feats
setPopUpMenu(handles.popupmenu_feat,monster.feat)




%--- Set pop-up menus
function setPopUpMenu(where, what)
original = what;
% if what empty
if isempty(what)
    return;
end

% Start reading
while 1
    % Get first trunk
    t = strclip(original,',',0);

    % If it is the last trunk
    if t == -1
        % Delete the ' ' from the begining
        if original(1)==' '
            original = original(2:end);
        end
        % Save 
        try
            if isempty(cell2mat(get(where,'string')))
                t2 = [{original}];
                set(where,'string',t2);
            else
                t2 = [get(where,'string'); {original} ];
                set(where,'string',t2);
            end
        catch
            t2 = [get(where,'string'); {original} ];
            set(where,'string',t2);
        end
        break;
    end
    % Delete first trunk
    original = strclip(original,',',1);
    % Delete the ' ' from the begining
    if t(1)==' '
        t = t(2:end);
    end
    % If it is the first
    if length(get(where,'string')) < 2
        % Save
        set(where,'string',t);
    else
        % Save
        t2 = [get(where,'string'); {t} ];
        set(where,'string',t2);            
    end
end

%--- Get pop-up menus
function s = getPopUpMenu(popUpMenu)
s = '';
original = get(popUpMenu,'string');
disp(['Original:' original])
Size = size(original,1)
try
    for i=1:Size
        s = [s original{i}];
        if i~=Size
            s = [s ', '];
        end
    end
catch
    s = '';
end
s



%--- Clear all values
function clear(handles)

set(handles.edit_name,'string','');
set(handles.edit_class,'string','');
set(handles.edit_initiative,'string','');
set(handles.edit_hp,'string','');
set(handles.edit_speed,'string','');
set(handles.edit_ac,'string','');

set(handles.edit_challenge,'string','');
set(handles.edit_treasure,'string','');
set(handles.edit_characteristic,'string','');
set(handles.edit_sidereach,'string','');

set(handles.edit_str,'string','');
set(handles.edit_dex,'string','');
set(handles.edit_con,'string','');
set(handles.edit_int,'string','');
set(handles.edit_wis,'string','');
set(handles.edit_cha,'string','');

set(handles.edit_for,'string','');
set(handles.edit_ref,'string','');
set(handles.edit_wil,'string','');

set(handles.popupmenu_attack,'string',{[]});
set(handles.popupmenu_sabilities,'string',{[]});
set(handles.popupmenu_sattack,'string',{[]});
set(handles.popupmenu_proficiency,'string',{[]});
set(handles.popupmenu_feat,'string',{[]});







% --- Executes on selection change in popupmenu_attack.
function popupmenu_attack_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu_attack (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu_attack contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu_attack


% --- Executes during object creation, after setting all properties.
function popupmenu_attack_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu_attack (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenu_sabilities.
function popupmenu_sabilities_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu_sabilities (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu_sabilities contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu_sabilities


% --- Executes during object creation, after setting all properties.
function popupmenu_sabilities_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu_sabilities (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenu_sattack.
function popupmenu_sattack_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu_sattack (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu_sattack contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu_sattack


% --- Executes during object creation, after setting all properties.
function popupmenu_sattack_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu_sattack (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenu_proficiency.
function popupmenu_proficiency_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu_proficiency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu_proficiency contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu_proficiency


% --- Executes during object creation, after setting all properties.
function popupmenu_proficiency_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu_proficiency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenu_feat.
function popupmenu_feat_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu_feat (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu_feat contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu_feat


% --- Executes during object creation, after setting all properties.
function popupmenu_feat_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu_feat (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --- Executes on button press in pushbutton_clear.
function pushbutton_clear_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_clear (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clear(handles)



% --- Executes on button press in pushbutton_generateAtt.
function pushbutton_generateAtt_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_generateAtt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Generate attributes
char = genatr( [] );

% Save attributes
set(handles.edit_str,'string',char.atr.str(1));
set(handles.edit_dex,'string',char.atr.dex(1));
set(handles.edit_con,'string',char.atr.con(1));
set(handles.edit_int,'string',char.atr.int(1));
set(handles.edit_wis,'string',char.atr.wis(1));
set(handles.edit_cha,'string',char.atr.cha(1));






% --- Executes on button press in pushbutton_hp.
function pushbutton_hp_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_hp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Throw
res = throwDices();

% Save result
if res>0
    set(handles.edit_hp,'string',res);
end


% Throw Dices
function res = throwDices()
while 1
    % Get parameters
    prompt = {'Enter the type of dices:','Enter the number of dices:',...
              'Enter the modifiers:'};
    dlg_title = 'Throw dices';
    num_lines = 1;
    answer = inputdlg(prompt,dlg_title,num_lines);
    if isempty(answer)
        res = -1;
        break;
    end
    try
        % Read inputs (last row is full with ones)
        M = [str2num(cell2mat(answer(1)));str2num(cell2mat(answer(2)));...
            str2num(cell2mat(answer(3)))];
        d = size(M,2);
        M = [M;ones(1,d)];

        % Throw
        res = kk(M);
        break;
    catch
        uiwait(errordlg('Wrong numbers! You have to write N number for each row!'));
    end
end

% Regenarate?
while 1
    ans = questdlg(['HP = ' num2str(res) '. Regenerate?']);
    if strcmp(ans,'Yes')
        res = kk(M);
    else
        break;
    end
end







function edit_challenge_Callback(hObject, eventdata, handles)
% hObject    handle to edit_challenge (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_challenge as text
%        str2double(get(hObject,'String')) returns contents of edit_challenge as a double


% --- Executes during object creation, after setting all properties.
function edit_challenge_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_challenge (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_treasure_Callback(hObject, eventdata, handles)
% hObject    handle to edit_treasure (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_treasure as text
%        str2double(get(hObject,'String')) returns contents of edit_treasure as a double


% --- Executes during object creation, after setting all properties.
function edit_treasure_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_treasure (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_characteristic_Callback(hObject, eventdata, handles)
% hObject    handle to edit_characteristic (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_characteristic as text
%        str2double(get(hObject,'String')) returns contents of edit_characteristic as a double


% --- Executes during object creation, after setting all properties.
function edit_characteristic_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_characteristic (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_sidereach_Callback(hObject, eventdata, handles)
% hObject    handle to edit_sidereach (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_sidereach as text
%        str2double(get(hObject,'String')) returns contents of edit_sidereach as a double


% --- Executes during object creation, after setting all properties.
function edit_sidereach_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_sidereach (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end





function edit_damage_Callback(hObject, eventdata, handles)
% hObject    handle to edit_damage (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_damage as text
%        str2double(get(hObject,'String')) returns contents of edit_damage as a double


% --- Executes during object creation, after setting all properties.
function edit_damage_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_damage (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


